package com.wanhe.callring.module.callring;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wanhe.callring.R;

/**
 * 呼叫服务Adapter
 * Created by XieZaiWei on 2017/2/16.
 */

public class CallRingAdapter extends BaseAdapter {
    private LayoutInflater mInflater;
    private String[] arrMsg;


    public CallRingAdapter(Context context) {
        mInflater = LayoutInflater.from(context);
        //数据可通过配置文件读取
        arrMsg = context.getResources().getStringArray(R.array.call_ring_message);
    }

    @Override
    public int getCount() {
        return arrMsg.length;
    }

    @Override
    public Object getItem(int position) {
        return arrMsg[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.call_ring_item, null);
            viewHolder.tv_message = (TextView) convertView.findViewById(R.id.tv_message);
            convertView.setTag(viewHolder);

        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.tv_message.setText(arrMsg[position]);

        return convertView;
    }

    public static class ViewHolder {
        public TextView tv_message;
    }
}
